package com.starsoft.frame.base.plugin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.starsoft.frame.base.bean.BaseAcount;
import com.starsoft.frame.base.service.AcountService;

@Component
public class AcountPluginImpl extends AbstractAcountPlugin {

	@Autowired
	AcountService acountService;

	@Override
	public String getName() {
		return "Base";
	}
	
	@Override
	public int getOrder(){
		return 0;
	}

	public BaseAcount create(BaseAcount acount) {
		acountService.saveAcount(acount);
		return acount;
	}
	

	@Override
	public void update(BaseAcount acount) {
	}

	@Override
	public void delete(BaseAcount acount) {
		acountService.deleteAcount(acount);
	}

	public BaseAcount copy(BaseAcount from, BaseAcount to) {
		if(to.getAcountName()==null){
			to.setAcountName("copy acount");
		}
		if(to.getUserId()==null){
			to.setUserId(from.getUserId());
		}
		if(to.getAcountDesc()==null){
			to.setAcountDesc("copy from acount:"+from.getAcountName());
		}
		acountService.saveAcount(to);
		return to;
	}

	@Override
	public BaseAcount copyAsSun(BaseAcount parent, BaseAcount sun) {
		copy(parent, sun);
		sun.setParentId(parent.getAcountId());
		acountService.saveAcount(sun);
		return sun;
	}

}
